#ifndef EDGE_H
#define EDGE_H

#include <QList>
#include <QPoint>


class Node;

class Edge
{
private:
    Node* m_from;
    Node* m_to;
    double m_cost;

public:

    void setCost(double cost)
    {
        m_cost=cost;
    }

    double getCost() const
    {
        return m_cost;
    }

    void setFrom(Node* from)
    {
        m_from=from;
    }

    Node* getFrom() const
    {
        return m_from;
    }

    void setTo(Node* to)
    {
        m_to=to;
    }

    Node* getTo() const
    {
        return m_to;
    }

    Edge(Node* from, Node* to, double cost):m_from(from),m_to(to),m_cost(cost){}
    Edge(Node* from, Node* to):m_from(from),m_to(to),m_cost(1.0){}

    bool operator == (Edge& x)
    {
        return (this->getFrom()==x.getFrom() && this->getTo()==x.getTo());
    }

};

class Node
{
private:

    int index;
    QPointF pos;


public:

    QList<Edge*> edges;

    Node(int i, QPointF p):index(i),pos(p){}

    QPointF getPos()
    {
        return pos;
    }

    int getIndex()
    {
        return index;
    }


    void addEdge(Edge* e)
    {
        foreach (Edge* x,  edges)
        {
            if ( *x == *e ) return;
        }

        if(e->getFrom()->getIndex()>=0&&e->getTo()->getIndex()>=0)
        {
            edges.push_back(e);
            e->getTo()->addEdge(new Edge(e->getTo(),this,e->getCost()));
        }
    }


};


#endif // EDGE_H
